package com.rockbb.common.sso.session;

import com.rockbb.common.sso.config.SSOConfig;

public class SessionConstants
{
	public static final long USER_ID_ANONYMOUS = 1;
	public static final long USER_UID_ANONYMOUS = 268435456L;

	public static final int SESSION_STORE_NATIVE = 0;
	public static final int SESSION_STORE_MEMCACHED = 1;

	public static final int SESSION_EXPIRE_MAX = 1209600; // In seconds, 3600 x 24 x 14

	public static final int SESSION_AUTOLOGIN_OFF = 0;
	public static final int SESSION_AUTOLOGIN_ON = 1;

	public static final int FACTORY_MODE_SERVER = 0;
	public static final int FACTORY_MODE_CLIENT = 1;
	public static final int FACTORY_SYNC_MODE_AUTH = 0;
	public static final int FACTORY_SYNC_MODE_SESSION = 1;

	public static final int FACTORY_SESSION_PULSE = 30;

	public static final String PARAM_MODE = "m";
	public static final int MODE_SESSION = 1;
	public static final int MODE_USER = 2;
	public static final int MODE_CLIENT_GETUSER = 3;
	public static final int MODE_CLIENT_ADDUSER = 4;

	public static final String PARAM_SID = "sid";
	public static final String PARAM_UID = "uid";
	public static final String PARAM_NAME = "name";
	public static final String PARAM_EMAIL = "email";
	public static final String PARAM_LANGUAGE = "language";
	public static final String PARAM_PASSWD = "passwd";
	public static final String PARAM_PERMISSIONS = "permissions";
	public static final String PARAM_STATUS = "status";
	public static final String PARAM_TIMEZONE = "timezone";
	public static final String PARAM_IP = "ip";
	public static final String PARAM_AGENT = "agt";
	public static final String PARAM_KEY = "key";
	public static final String PARAM_MESSAGE = "msg";
	public static final String PARAM_TOKEN_HASH = "sha";
	public static final String PARAM_RANDOM = "rand";
	public static final String PARAM_REALTIME = "realtime";
	public static final String PARAM_REDIRECT = "redirect";

	public static final int AUTH_FLAG_SUCCESS = 0;
	public static final int AUTH_FLAG_ERROR = 1;

	// Cookie prefix. For different applications under the same domain
	public static final String COOKIE_KEY = SSOConfig.getValue("cookie.prefix");

	// HashMap:0 Memcached:1
	public static final int SESSION_STORAGE = SSOConfig.getIntValue("session.storage");

	// Local session mode: host or client
	public static final int SESSION_MODE = (SSOConfig.getIntValue("session.mode") == FACTORY_MODE_SERVER) ? FACTORY_MODE_SERVER
			: FACTORY_MODE_CLIENT;

	// Session expire time for registered users
	public static final int SESSION_EXPIRE = SSOConfig.getIntValue("session.expire");

	// Session expire time for anonymous users
	public static final int SESSION_EXPIRE_ANONYMOUS = SSOConfig.getIntValue("session.expire.anonymous");

	// The session cleaner will remove the idle sessions in an interval of the specified seconds
	public static final int SESSION_CLEAN_INTERVAL = SSOConfig.getIntValue("session.clean_interval");

	// Client name will be used in session sync with SSO server
	public static final String SESSION_CLIENT_KEY = SSOConfig.getValue("session.client_key");

	// Client token will be used in session sync with SSO server
	public static final String SESSION_CLIENT_TOKEN = SSOConfig.getValue("session.client_token");

	// The server side interface for sync information fetching
	public static final String SESSION_SYNC_ADDR = SSOConfig.getValue("session.sync_address");

	// The sync mode can be auth or session. In the auth mode, the client maintains its sessions itself.
	public static final int SESSION_SYNC_MODE = (SSOConfig.getIntValue("session.sync_mode") == FACTORY_SYNC_MODE_SESSION) ? FACTORY_SYNC_MODE_SESSION
			: FACTORY_SYNC_MODE_AUTH;

	// Enable the IP verification or not. 0:OFF, 1:ON
	public static final int AUTH_WITH_IP = SSOConfig.getIntValue("session.auth_with_ip");

	// Style id on SSO server ( for this client app )
	public static final int TEMPLATE_STYLE = SSOConfig.getIntValue("session.template_style");
}
